﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EnvironmentManagerSystem.BLL;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.Utility;

namespace EnvironmentManagerSystem.ExpertManager
{
    public partial class ExpertManagerPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                BingData();

                #region 用户权限
                if ((Boolean)Session["Admin"])
                {
                    if (!(Boolean)Session["Admin"])
                    {
                        Button1.Visible = false;
                        btnReBind.Visible = false;
                        gdvUser.Columns[5].Visible = false;
                    }
                    else
                    {
                        Button1.Visible = true;
                        btnReBind.Visible = true;
                        gdvUser.Columns[5].Visible = true;
                    }
                }
                else if ((Boolean)Session["xmfzr"])
                {
                    if (!(Boolean)Session["xmfzr"])
                    {
                        Button1.Visible = false;
                        btnReBind.Visible = false;
                        gdvUser.Columns[5].Visible = false;
                    }
                    else
                    {
                        Button1.Visible = true;
                        btnReBind.Visible = true;
                        gdvUser.Columns[5].Visible = true;
                    }
                }
                else
                {
                    Button1.Visible = false;
                    btnReBind.Visible = false;
                    gdvUser.Columns[5].Visible = false;
                }
                #endregion
            }
        }

        public void BingData()
        {
            gdvUser.DataSource = Expert.GetListTable();
            gdvUser.DataBind();
        }
        //分页事件
        protected void gdvUser_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gdvUser.PageIndex = e.NewPageIndex;
        }

        //分页后事件
        protected void gdvUser_PageIndexChanged(object sender, EventArgs e)
        {
            //BingSubKind();
            //BingData();
            SelectBind();
        }

        //编辑事件
        protected void gdvUser_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //gdvUser.EditIndex = e.NewEditIndex;
            //BingSubKind(); BingData();
            //BingData();

        }

        //取消事件
        protected void gdvUser_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gdvUser.EditIndex = -1;
            //BingSubKind();
            BingData();
        }

        //更新事件
        protected void gdvUser_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }

        //删除事件
        protected void gdvUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (Expert.DelByID(gdvUser.DataKeys[e.RowIndex].Value.ToString()) > 0)
            {
                Jscript.Alert("删除成功", this);
                BingData();
            }
            else
            {
                Jscript.Alert("删除失败", this);
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {

        }
        protected void gdvUser_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());
            }
        }

        protected void btnReBind_Click(object sender, EventArgs e)
        {
            BingData();
        }
        //鼠标滑动
        protected void gdvUser_DataBound(object sender, EventArgs e)
        {
            OfficeHelper.HelpDv(gdvUser);
        }

        #region 专家查询
        protected void btn_Select_Click(object sender, EventArgs e)
        {
            SelectBind();
        }

        private void SelectBind()
        {
            gdvUser.DataSource = Expert.GetSelectName(tb_Name.Text, tb_Work.Text);
            gdvUser.DataBind();
        }
        #endregion
    }
}
